package com.pub.cloud.system.status.config;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

/**
 * 定时任务并行执行
 **/
@Configuration
public class ScheduledConfig implements SchedulingConfigurer {
	@Value("${scheduled-thread-pool}")
	private int scheduledThreadPool;

	@Override
	public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
		scheduledTaskRegistrar.setScheduler(setTaskExecutors());
	}
//
	@Bean(destroyMethod = "shutdown")
	public Executor setTaskExecutors() {
		return Executors.newScheduledThreadPool(scheduledThreadPool); // scheduledThreadPool个线程来处理。
//		return Executors.newScheduledThreadPool(1);
	}
}
